/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wider.foundation;

import java.lang.reflect.Array;
import java.util.Iterator;

/**
 * This class defines a wrapper class to make an object of array to be Iterable.
 * 
 * @author William Choi <avextk@gmail.com>
 */
public class ArrayX<T> implements Iterator<T>, Iterable{
    private Object  array;
    private long    curri;
    private long    arlen;

    public ArrayX(Object theArray){
        array = theArray;
        curri = 0;
        arlen = Array.getLength(array);
    }

    @Override
    public boolean hasNext() {
        return (curri < arlen);
    }

    @Override
    public T next() {
        return (T) Array.get(array, (int) (curri++));
    }

    @Override
    public void remove() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Iterator iterator() {
        return this;
    }
}
